
local event_list =_G.ServerOHOH.event_list
local M=_G.ServerOHOH.class.new(script,  _G.ServerOHOH.files.Server_PlayerComponent(),script.Parent.Name);
local GeneralTool=_G.CommonOHOH.load.GeneralTool();
local Battle_Cfg=_G.CommonOHOH.config.Chapter.chapter2level

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.player=self.parent
    self.DataStore=self.parent:GetComponent(_G.ServerOHOH.load.Server_PlayerDataComponent())
	self.ItemCtrl=self.player:GetComponent(_G.ServerOHOH.load.Server_ItemCtrl())
end;


--计算luck值
function M.GetLuckyValue(self)
	local baseList= self.player.LuckyValueBaseEvent:Action()
	local mulList=  self.player.LuckyValueMulEvent:Action()
	local addList=  self.player.LuckyValueAddEvent:Action()

	local base=0
	for _,v in pairs(baseList) do
		 base=base+v
	end
 
	local mul=1
	for _,v in pairs(mulList) do
		 mul=mul+v
	end

	local add=0
	for _,v in pairs(addList) do
		  add=add+v
	 end
	
	 local v=base*mul+add
 	return v
end


--计算掉落武器
function M.GetWeapon(self,weight,weapon,levelId)
	local baseLucky=self:GetLuckyValue()
	local lucky=baseLucky

	--增加关卡幸运值
	local levelAdd=levelId%30
	if levelAdd==0 then
		levelAdd=30
	end
	lucky=lucky+levelAdd

	local index=GeneralTool.RandomLucky(weight,lucky)
	local cid= weapon[index]

	print("--------------掉落武器删除-----------B-----------------",cid)
	_G.CommonOHOH:PrintTable(self.deletData)


	if self.deletData and self.deletData[cid] then
		return 
	end
	return cid
end


function M.DropWeapon(self,battleId,levelId)
	local cfg= Battle_Cfg[battleId]
	-- local weight,weapon
	local wid=self:GetWeapon(cfg.weight,cfg.weapon,levelId)
	if wid then
		local itemId="weapon_"..wid.."_1"
		self.ItemCtrl:AddAnyThing(itemId,1,false,false)

		self.player:SynchDataToClient("weapon");

		self:Fire(event_list.weapon_drop,wid)
	end

end

function M.deletData(self,deletData)
	self.deletData=deletData
	print("--------------掉落武器删除-----------A-----------------")
	_G.CommonOHOH:PrintTable(self.deletData)
end

function M.dtor(self)
	M.super.dtor(self);
end;


M:RegistEvent(event_list.delete_data,M.deletData)


return M